class Solution:
    def isValid(self, s: str) -> bool:
        S = list()
        for i in s:
            if i == '(' or i == '[' or i == '{':
                S.append(i)
            else:
                if S == []:
                    return False
                if i == ')' and S[-1] == '(' or  i == ']' and S[-1] == '[' or i == '}' and S[-1] == '{':
                    S.pop(-1)
                else:
                    return False
        if S == []:
            return True
        else:
            return False

if __name__ == '__main__':
    s = Solution()
    print(s.isValid('()[]{}'))
    print(s.isValid('(]'))
    print(s.isValid('([)]'))
    print(s.isValid('{[]}'))
    print(s.isValid('('))
    print(s.isValid(')'))